package com.kotlin.user.service.impl

import com.kotlin.base.data.protocol.BaseResp
import com.kotlin.base.rx.BaseException
import com.kotlin.user.data.repository.UserRepository
import com.kotlin.user.service.UserService
import rx.Observable
import rx.functions.Func1
import javax.inject.Inject

/**
 * @author Mr.Wang
 * @version v0.3.6
 * @time 2018/3/7
 * @describe
 */
class UserServiceImpl @Inject constructor():UserService{

    @Inject
    lateinit var repository:UserRepository

    override fun register(mobile: String, pwd: String): Observable<Boolean> {

        return repository.register(mobile,pwd)
               .flatMap(object :Func1<BaseResp<String>,Observable<Boolean>>{
                   override fun call(t:BaseResp<String>): Observable<Boolean>{
                       if (t.status != 0){
                             return Observable.error(BaseException(t.status,t.message))
                       }
                       return Observable.just(true)
                   }
               })
    }

}